-
-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set Default Schema to Remote Schema #777
base: main
Are you sure you want to change the base?
Conversation
@coderabbitai full review |
📝 Walkthrough📝 WalkthroughWalkthroughThe changes introduce a new constant, Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
internal/exec/validate_stacks.go (2)
89-110
: LGTM! Clear and robust schema validation logicThe implementation effectively handles the default schema setting and provides comprehensive error handling. The trace logging helps with debugging, and the error message is informative.
A small enhancement suggestion: Consider adding the default schema URL to the error message to make it clear what URL will be used if none is specified.
Here's the suggested improvement for the error message:
return fmt.Errorf("the Atmos JSON Schema file '%s' does not exist.\n"+ "It can be configured in the 'schemas.atmos.manifest' section in 'atmos.yaml', or provided using the 'ATMOS_SCHEMAS_ATMOS_MANIFEST' "+ "ENV variable or '--schemas-atmos-manifest' command line argument.\n"+ "The path to the schema file should be an absolute path or a path relative to the 'base_path' setting in 'atmos.yaml'. \n"+ - "Alternatively, you can specify a schema file using a URL that will be downloaded automatically.", + "Alternatively, you can specify a schema file using a URL that will be downloaded automatically.\n"+ + "If not specified, the default schema URL '%s' will be used.", - cliConfig.Schemas.Atmos.Manifest) + cliConfig.Schemas.Atmos.Manifest, atmosManifestDefault)
100-103
: Consider adding retry mechanism for schema downloadsNetwork requests to download the schema can fail temporarily. Consider implementing a retry mechanism with exponential backoff for better reliability.
Example implementation using a simple retry loop:
+func downloadWithRetry(client *getter.Client, maxRetries int) error { + var err error + for i := 0; i < maxRetries; i++ { + if err = client.Get(); err == nil { + return nil + } + time.Sleep(time.Second * time.Duration(1<<uint(i))) + } + return err +} func downloadSchemaFromURL(manifestURL string) (string, error) { // ... existing code ... - if err = client.Get(); err != nil { + if err = downloadWithRetry(client, 3); err != nil { return "", fmt.Errorf("failed to download the Atmos JSON Schema file '%s' from the URL '%s': %w", fileName, manifestURL, err) } return atmosManifestJsonSchemaFilePath, nil }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
internal/exec/validate_stacks.go
(2 hunks)
🔇 Additional comments (1)
internal/exec/validate_stacks.go (1)
22-23
: Consider making the schema version configurable
The hardcoded version 1.0
in the URL might make future schema updates challenging. Consider making the version configurable or using version negotiation.
Let's verify if this schema URL is accessible and returns valid JSON:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (1)
internal/exec/validate_stacks.go (1)
105-110
: Consider making the error message more concise.The current error message is quite verbose. Consider restructuring it to be more scannable while maintaining the essential information.
- return fmt.Errorf("the Atmos JSON Schema file '%s' does not exist.\n"+ - "It can be configured in the 'schemas.atmos.manifest' section in 'atmos.yaml', or provided using the 'ATMOS_SCHEMAS_ATMOS_MANIFEST' "+ - "ENV variable or '--schemas-atmos-manifest' command line argument.\n"+ - "The path to the schema file should be an absolute path or a path relative to the 'base_path' setting in 'atmos.yaml'. \n"+ - "Alternatively, you can specify a schema file using a URL that will be downloaded automatically.", + return fmt.Errorf("Schema file '%s' not found. Configure via:\n"+ + "1. 'schemas.atmos.manifest' in atmos.yaml\n"+ + "2. ATMOS_SCHEMAS_ATMOS_MANIFEST env var\n"+ + "3. --schemas-atmos-manifest flag\n\n"+ + "Accepts: absolute path, relative to base_path, or URL", cliConfig.Schemas.Atmos.Manifest)
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
internal/exec/validate_stacks.go
(2 hunks)
🔇 Additional comments (2)
internal/exec/validate_stacks.go (2)
89-92
: LGTM! Default schema assignment is solid.
The implementation gracefully handles empty schema configuration by setting a default and providing clear trace logging.
22-22
: LGTM! Let's verify the schema URL accessibility.
The constant declaration is well-named and follows Go conventions.
Let's verify the schema URL is accessible and returns valid JSON:
✅ Verification successful
Schema URL is valid and accessible 🛡️
The default schema URL is properly configured and returns valid JSON. The constant can be safely used as the default schema location for manifest validation.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify schema URL accessibility and JSON validity
curl -s -f -L https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json | jq . >/dev/null
if [ $? -eq 0 ]; then
echo "Schema URL is accessible and returns valid JSON"
else
echo "Failed to validate schema URL"
fi
Length of output: 218
@haitham911 please share a screenshot of it working and of the error message |
cliConfig.Schemas.Atmos.Manifest) | ||
if cliConfig.Schemas.Atmos.Manifest == "" { | ||
cliConfig.Schemas.Atmos.Manifest = atmosManifestDefault | ||
u.LogInfo(cliConfig, fmt.Sprintf("The Atmos JSON Schema file is not configured. Using the default schema '%s'", atmosManifestDefault)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change to debug level, since it's not important enough to output every time.
what
if schemas.atmos.manifest empty atmos validate not work work.
if schemas.atmos.manifest empty is set Default Schema to Remote Schema .
default remote url https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json
why
We should set the default schema to the remote atmos schema so that atmos validate work
references
DEV-2727
https://linear.app/cloudposse/issue/DEV-2727/set-default-schema-to-remote-schema
DEV-2720
https://linear.app/cloudposse/issue/DEV-2720/error-if-remote-schema-for-validation-not-set
Summary by CodeRabbit
New Features
Improvements